/**
 * Created by gongxun on 17/1/13.
 */

var NnTableUILayer = GameCCSBase.extend({
    mNnTableMicLayer : null,
    mNnTablePlayerInfoLayer : null,
    mNnTableChatLayer : null,
    mNnTableSettingLayer : null,
    mNnTableEndLayer : null,

    Panel_ready : null,
    Panel_bet : null,
    Panel_otc : null,
    Panel_cardType : null,
    Image_userControlTips : null,
    Panel_playeAnim : null,
    Panel_time : null,

    mButton_bets : null,
    mCardTypes : null,
    mPlayer : null,
    mPlayerPoss : null,
    mPlayerInfos : null,

    //网络延迟
    mKwxSysInfoWidget : null,
    Image_ipwarring : null,

    //踢人按钮
    Button_kick1 : null,
    Button_kick2 : null,
    Button_kick3 : null,
    Button_kick4 : null,

    //倒计时
    Image_timeBg : null,
    mTimeLeft : null,
    mProgressTimer : null,
    ctor : function(){
        this._super();
        this.loadCocostudio("res/ccs/NnTableUI.json");
        this.Panel_ready = mo.seekWidgetByName(this.ccsNode, "Panel_ready");
        this.Panel_bet = mo.seekWidgetByName(this.ccsNode, "Panel_bet");
        this.Panel_otc = mo.seekWidgetByName(this.ccsNode, "Panel_otc");
        this.Panel_cardType = mo.seekWidgetByName(this.ccsNode, "Panel_cardType");
        this.Image_userControlTips = mo.seekWidgetByName(this.ccsNode, "Image_userControlTips");
        this.Panel_playeAnim = mo.seekWidgetByName(this.ccsNode, "Panel_playeAnim");
        this.Panel_time = mo.seekWidgetByName(this.ccsNode, "Panel_time");
        this.Button_kick1 = mo.seekWidgetByName(this.ccsNode, "Button_kick1");
        this.Button_kick2 = mo.seekWidgetByName(this.ccsNode, "Button_kick2");
        this.Button_kick3 = mo.seekWidgetByName(this.ccsNode, "Button_kick3");
        this.Button_kick4 = mo.seekWidgetByName(this.ccsNode, "Button_kick4");
        this.Image_timeBg = mo.seekWidgetByName(this.ccsNode, "Image_timeBg");
        this.Image_ipwarring = mo.seekWidgetByName(this.ccsNode, "Image_ipwarring");

        //设置
        mo.seekWidgetByName(this.ccsNode, "Button_setting").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.mNnTableSettingLayer.setDialog(true);
            }
        }, this);

        //规则
        mo.seekWidgetByName(this.ccsNode, "Button_rule").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.addChild(new NnTableRuleLayer());
            }
        }, this);

        this.loadUI();
    },

    onEnter : function(){
        this._super();

        mo.eventHelper.add("UserChatMsgResponse", this, function(userChatMsgResponse){
            this.setChatMsg(userChatMsgResponse);
        });

        mo.eventHelper.add("UserOnLineChange", this, function(onlineInfo){
            this.setPlayerOnlineStats(onlineInfo);
        });

        mo.eventHelper.add("UserChatMsgResponse_reward", this, function(userChatMsgResponse){
            this.setChatMsgReward(userChatMsgResponse);
        });
    },

    onExit : function(){
        mo.eventHelper.remove(this);
        this._super();
    },

    loadUI : function(){
        if (cc.sys.isNative){
            this.mNnTableMicLayer = new NnTableMicLayer();
            this.addChild(this.mNnTableMicLayer);
        }

        //个人信息
        this.mNnTablePlayerInfoLayer = new KwxTablePlayerInfoLayer();
        this.addChild(this.mNnTablePlayerInfoLayer);

        this.mNnTableChatLayer = new KwxDialogChat();
        this.mNnTableChatLayer.setChatButton(mo.seekWidgetByName(this.ccsNode, "Button_chat"), "nn");
        this.addChild(this.mNnTableChatLayer);

        this.mNnTableSettingLayer = new KwxDialogSetting("nn");
        this.addChild(this.mNnTableSettingLayer);

        this.mNnTableEndLayer = new NnTableEndLayer();
        this.addChild(this.mNnTableEndLayer);

        ///准备
        mo.seekWidgetByName(this.Panel_ready, "Button_start").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.gameMsgManager.sendGameReadyRequestnn();
            }
        }, this);

        mo.seekWidgetByName(this.Panel_ready, "Button_invite").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.nnTable.onInvite();
            }
        }, this);

        mo.seekWidgetByName(this.Panel_ready, "Button_disband").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                var isStart = mo.nnTable.mGameConfig.maxpan != mo.nnTableStatus.mTableStatus.LeftPlayTimes;
                if (!isStart){
                    mo.showMsgDialogOkAndCancel("确定退出房间吗？\n牌局未开始退出不会消耗房卡\n房主退出会解散牌桌", function(){
                        if (mo.nnTable.mGameConfig.maxpan == mo.nnTableStatus.mTableStatus.LeftPlayTimes){
                            mo.gameMsgManager.sendForceExitTableRequestnn();
                        }
                    }, this, function(){}, this);
                }
                // mo.nnTable.mNnTableCancelLayer.sendCancelTableAgree();
            }
        }, this);

        //踢人
        this.Button_kick1.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(1);
            }
        }, this);

        this.Button_kick2.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(2);
            }
        }, this);
        this.Button_kick3.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(3);
            }
        }, this);

        this.Button_kick4.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(4);
            }
        }, this);

        ///下注
        this.mButton_bets = [];
        for(var i = 0; i < 5; i++){
            var Button_bet = mo.seekWidgetByName(this.Panel_bet, "Button_bet" + i);
            this.mButton_bets.push(Button_bet);

            Button_bet.setTag(i);
            Button_bet.addTouchEventListener(function(sender, type){
                if (mo.gameHelper.getIsTouchEnd(type)) {
                    var index = sender.getTag();
                    mo.nnTableStatus.sendMyBet(index);
                }
            }, this);
        }

        ///开牌
        mo.seekWidgetByName(this.Panel_otc, "Button_niuWu").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                var myAction = mo.nnTableStatus.getMySelectCards();
                if (myAction == null){
                    return;
                }

                var autoSend = [
                    14,
                    41,
                    21,
                    23,
                    25,
                    27,
                    29,
                    31,
                    33,
                    35,
                    37,
                    39
                ];

                if (mo.gameHelper.findValueForArray(autoSend, myAction.Rate) != null){
                    mo.nnTableStatus.sendActionSelect();
                }else{
                    mo.showRoomMsgShow("确定没有牛吗？要不再想想");
                }
            }
        }, this);

        mo.seekWidgetByName(this.Panel_otc, "Button_niuTishi").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                var myAction = mo.nnTableStatus.getMySelectCards();
                if (myAction == null){
                    return;
                }
                mo.nnTableStatus.sendActionSelect();
                return;

                var autoSend = [
                    14,
                    41,
                    21,
                    23,
                    25,
                    27,
                    29,
                    31,
                    33,
                    35,
                    37,
                    39
                ];

                if (mo.gameHelper.findValueForArray(autoSend, myAction.Rate) != null){
                    mo.nnTableStatus.sendActionSelect();
                }else{
                    mo.nnTable.mNnTableCardLayer.updateSelectCardStatus();
                }
            }
        }, this);

        mo.seekWidgetByName(this.Panel_otc, "Button_niuYou").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.nnTableStatus.sendActionSelect();
            }
        }, this);

        //设置开牌位置
        if (mo.gameSize.x / mo.gameSize.y <= 1000 / 640){
            mo.seekWidgetByName(this.Panel_otc, "Button_niuWu").setPosition(cc.p(mo.gameSize.x / 2 + 90, 230));
            mo.seekWidgetByName(this.Panel_otc, "Button_niuYou").setPosition(cc.p(mo.gameSize.x / 2 + 90, 230));
            mo.seekWidgetByName(this.Panel_otc, "Button_niuTishi").setPosition(cc.p(mo.gameSize.x / 2, 230));
        }

        ///牌类型
        this.mCardTypes = [];
        for (var i = 0; i < 5; i++){
            var Panel_cardType = mo.seekWidgetByName(this.Panel_cardType, "Panel_cardType" + i);
            var nnTableCardType = new NnTableCardType();
            this.mCardTypes.push(nnTableCardType);
            Panel_cardType.addChild(nnTableCardType);
        }

        ///用户
        this.mPlayer = [];
        this.mPlayerPoss = [];
        var Panel_player = mo.seekWidgetByName(this.ccsNode, "Panel_player");
        for(var i = 0; i < 5; i++){
            var player = mo.seekWidgetByName(Panel_player, "Panel_player" + i);
            var playerItem = new NnTablePlayer(i);
            player.addChild(playerItem);
            this.mPlayer.push(playerItem);

            this.mPlayerPoss.push(cc.pAdd(player.getPosition(), cc.p(0, 45)));
        }

        //倒计时
        this.mProgressTimer = new cc.ProgressTimer(new cc.Sprite("res/ccs/nn/leftTime_bg1.png"));
        this.mProgressTimer.type = cc.ProgressTimer.TYPE_RADIAL;
        this.mProgressTimer.setReverseDirection(true);
        this.mProgressTimer.setPosition(cc.p(this.Image_timeBg.getContentSize().width / 2, this.Image_timeBg.getContentSize().height / 2));
        this.Image_timeBg.addChild(this.mProgressTimer);

        //wifi控件
        this.mKwxSysInfoWidget = new KwxSysInfoWidget();
        mo.seekWidgetByName(this.ccsNode, "Panel_wifi").addChild(this.mKwxSysInfoWidget);
    },

    //控制显示
    //index 1未开始  10:进来的状态 11:结算的状态
    //index 2下注    20:房主下注 21:普通玩家开始下注 22:普通玩家下注后
    //index 3开牌    30:准备开牌 31:等待别人开牌
    //index 4结算动画 40:结算动画
    intoShowIndex : function(index){
        if (index < 20){
            if (index == 10){
                this.Panel_ready.setVisible(true);
                this.Panel_bet.setVisible(false);
                this.Panel_otc.setVisible(false);
                this.Panel_cardType.setVisible(false);
                this.Image_userControlTips.setVisible(false);
                this.Panel_time.setVisible(false);
            }else if(index == 11){
                this.Panel_ready.setVisible(true);
                this.Panel_bet.setVisible(false);
                this.Panel_otc.setVisible(false);
                this.Image_userControlTips.setVisible(false);
                this.Panel_time.setVisible(false);

                //是否打了一局了 邀请和退出按钮的显示
                var isPlay = mo.nnTableStatus.mTableStatus.LeftPlayTimes != mo.nnTable.mGameConfig.maxpan;
                var Button_invite = mo.seekWidgetByName(this.Panel_ready, "Button_invite");
                var Button_disband = mo.seekWidgetByName(this.Panel_ready, "Button_disband");
                Button_invite.setVisible(!isPlay);
                Button_disband.setVisible(!isPlay);

                //自己是否准备
                var myIsReady = mo.nnTableStatus.getMyIsReady();
                if (myIsReady){
                    this.mNnTableEndLayer.setVisible(false);
                }

                //准备按钮显示
                var Button_start = mo.seekWidgetByName(this.Panel_ready, "Button_start");
                if (!isPlay){
                    //还没有开始
                    if (mo.nnTableStatus.mTableStatus.StartGameSeat == mo.nnTableStatus.mTableStatus.MySeat){
                        //自己是开房负责人
                        Button_start.setVisible(true);
                        Button_start.setEnabled(mo.nnTableStatus.getPlayerCount() >= 2);
                        Button_invite.setPositionX(mo.gameSize.x * 0.3);
                        Button_disband.setPositionX(mo.gameSize.x * 0.7);
                    }else{
                        Button_start.setVisible(false);
                        Button_invite.setPositionX(mo.gameSize.x * 0.4);
                        Button_disband.setPositionX(mo.gameSize.x * 0.6);
                    }
                }else{
                    //已经开始
                    Button_start.setPositionX(mo.gameSize.x / 2);
                    Button_start.setEnabled(true);
                    if (isPlay){
                        Button_start.setVisible(false);
                    }else{
                        Button_start.setVisible(!myIsReady);
                    }
                }

                //处理同ip显示问题
                var ipEquals = mo.nnTableStatus.getPlayerIpEqual();
                if (ipEquals.length > 0 && !isPlay){
                    this.Image_ipwarring.setVisible(true);
                    for (var i = 0; i < 5; i++){
                        var Panel_ip = mo.seekWidgetByName(this.Image_ipwarring, "Panel_ip" + i);
                        if (ipEquals.length > i){
                            Panel_ip.setVisible(true);
                            mo.gameHelper.setTextString(mo.seekWidgetByName(Panel_ip, "Text_ip_nick"), ipEquals[i].nick);
                            mo.gameHelper.setTextString(mo.seekWidgetByName(Panel_ip, "Text_ip_ip"), ipEquals[i].ip);
                        }else {
                            Panel_ip.setVisible(false);
                        }
                    }
                }else{
                    this.Image_ipwarring.setVisible(false);
                }
            }

            //能否显示踢人
            if (mo.nnTableStatus.mTableStatus != null && mo.nnTable.mGameConfig != null){
                var isPlay = mo.nnTableStatus.mTableStatus.LeftPlayTimes != mo.nnTable.mGameConfig.maxpan;
                var funcShowKick = function(viewSeat){
                    if (isPlay){
                        return false;
                    }

                    var logicSeat = mo.nnTableStatus.getLogicForView(viewSeat, mo.nnTableStatus.mTableStatus.MySeat - 1) + 1;
                    return mo.nnTable.mIsRoomCreator && mo.nnTableStatus.mTableStatus["SeatUser" + logicSeat] != null;
                };

                this.Button_kick1.setVisible(funcShowKick(1));
                this.Button_kick2.setVisible(funcShowKick(2));
                this.Button_kick3.setVisible(funcShowKick(3));
                this.Button_kick4.setVisible(funcShowKick(4));
            }

        }else if (index < 30){

            this.Panel_ready.setVisible(false);
            this.Panel_bet.setVisible(true);
            this.Panel_otc.setVisible(false);
            this.Panel_cardType.setVisible(false);
            this.Image_userControlTips.setVisible(false);
            this.Panel_time.setVisible(false);

            if (index == 21){
                this.Panel_bet.setVisible(true);
            }else if (index == 22){
                this.Panel_bet.setVisible(false);
                this.Image_userControlTips.setVisible(true);
                mo.gameHelper.loadTextureImage(this.Image_userControlTips, "res/ccs/nn/tips_xiazhu.png")
            }

        }else if (index < 40){

            this.Panel_ready.setVisible(false);
            this.Panel_bet.setVisible(false);
            this.Panel_otc.setVisible(true);
            this.Panel_cardType.setVisible(true);
            this.Image_userControlTips.setVisible(false);

            if (index == 30){
                this.Panel_otc.setVisible(true);
                this.Panel_time.setVisible(true);

                //启动倒计时
                if (this.mLastIndex != index){
                    this.mTimeLeft = 10.0;
                    this.schedule(this.ontUpdateTimeLeft);
                }

            }else if (index == 31){
                this.Panel_otc.setVisible(false);
                this.Panel_time.setVisible(false);
                this.Image_userControlTips.setVisible(true);
                this.unschedule(this.ontUpdateTimeLeft);
                mo.gameHelper.loadTextureImage(this.Image_userControlTips, "res/ccs/nn/tips_kaipai.png")
            }
        }

        this.mLastIndex = index;
    },

    //开牌 -1不显示
    setkaiPaiAnim : function(cardTypes){
        for (var i = 0; i < 5; i++){
            this.mCardTypes[i].showAnim(cardTypes[i]);
        }
    },

    //开牌
    setKaipaiOnePlayer : function(cardType, cardNums, seat){
        this.mCardTypes[seat].showAnim(cardType);
    },

    //输赢金币动画
    setScoreAnim : function(scores, hostSeat){
        this.Panel_playeAnim.removeAllChildren();

        var delayTime = 1;
        //动画全
        for (var seat = 0; seat < 5; seat++){
            var score = scores[seat];
            if (score == -9999){
                continue;
            }

            this.mPlayer[seat].showAddScoreAnim(score, delayTime);
            if (seat != hostSeat){
                if (score > 0){
                    this.setScoreMovoTo(hostSeat, seat, delayTime);
                }else{
                    this.setScoreMovoTo(seat, hostSeat, delayTime);
                }
            }
        }
        return delayTime + 1;
    },

    //飞金币
    setScoreMovoTo : function(formSeat, toSeat, delayTime){
        var coins = [];
        for (var i = 0; i < 4; i++){
            var coin = new cc.Sprite("res/ccs/nn/gold.png");
            coin.setScale(0.6);
            coin.setVisible(false);
            this.Panel_playeAnim.addChild(coin);

            var posOffset = cc.p(Math.random() * 30 - 15, Math.random() * 30 - 15);
            var formPos = cc.pAdd(this.mPlayerPoss[formSeat], posOffset);
            var toPos = cc.pAdd(this.mPlayerPoss[toSeat], posOffset);
            var distance = cc.pDistance(formPos, toPos);
            var speed = 2000;
            time = distance / speed + i * 0.05 + delayTime;

            coin.setPosition(formPos);
            coin.runAction(cc.sequence(
                cc.delayTime(i * 0.05 + delayTime),
                cc.callFunc(function(){
                    mo.soundHelper.playNnGetCoins();
                }, coin),
                cc.show(),
                cc.moveTo(0.5, toPos),
                cc.hide()
            ));
        }
    },

    //设置牌桌用户信息
    setTablePlayerInfos : function(infos){
        this.mPlayerInfos = infos;
        for (var i = 0; i < 5; i++){
            this.mPlayer[i].setPlayerInfo(infos[i]);
        }
    },

    //chat
    setChatMsg : function(userChatMsg){
        var seat = mo.nnTableStatus.getViewSeatForUid(userChatMsg.uid);
        var Panel_chat = this.mPlayer[seat].Panel_chat;
        Panel_chat.stopAllActions();

        var Image_chat = mo.seekWidgetByName(Panel_chat, "Image_chat");
        var Panel_audio = mo.seekWidgetByName(Panel_chat, "Panel_audio");
        var Text_content = mo.seekWidgetByName(Panel_chat, "Text_content");
        var Sprite_face = mo.seekWidgetByName(Panel_chat, "Sprite_face");

        Panel_chat.setVisible(false);
        Image_chat.setVisible(false);
        Sprite_face.setVisible(false);
        Panel_audio.setVisible(false);
        Text_content.setVisible(false);

        if (userChatMsg.type == 1){
            //处理文字消息
            var numIndex = parseInt(userChatMsg.msg);

            if (numIndex >=0 && numIndex < 13){
                //播放音效
                var sex = mo.nnTableStatus.getSexForUid(userChatMsg.uid);
                mo.soundHelper.playUserCustom(sex, numIndex);

                //快捷短语
                Text_content.setVisible(true);
                mo.gameHelper.setTextString(Text_content, mo.gameUserInfo.userCustomText[numIndex]);
                var sizeW = Text_content.getContentSize().width + 40;
                sizeW = Math.max(sizeW, 70);
                Text_content.setPositionX(sizeW / 2);

                Panel_chat.setVisible(true);
                Image_chat.setVisible(true);
                Image_chat.setContentSize(cc.size(sizeW, 64));

                Panel_chat.runAction(
                    cc.sequence(
                        cc.delayTime(3.0),
                        cc.hide()
                    )
                );
            }else if (numIndex >= 51 && numIndex < 80){

                //表情
                Sprite_face.setVisible(true);
                var animation = new cc.Animation(mo.nnCardHelper.getFaceFrames(numIndex - 51));
                animation.setDelayPerUnit(0.2);
                Sprite_face.stopAllActions();
                Sprite_face.runAction(cc.repeatForever(cc.animate(animation)));

                Panel_chat.setVisible(true);

                Panel_chat.runAction(
                    cc.sequence(
                        cc.delayTime(3.0),
                        cc.hide(),
                        cc.callFunc(function(){
                            Sprite_face.stopAllActions();
                        }, Panel_chat)
                    )
                );
            }else{
                Panel_chat.setVisible(false);

                var formSeat = seat;
                var toSeat = mo.nnTableStatus.getViewForLogic(numIndex % 10, mo.nnTableStatus.mTableStatus.MySeat - 1);
                var index = (parseInt(numIndex / 10) % 10);
                var p1 = this.mPlayerPoss[formSeat];
                var p2 = this.mPlayerPoss[toSeat];

                this.mNnTablePlayerInfoLayer.showEffectChat(formSeat, toSeat, index, p1, p2);
            }
        }else{
            if (!cc.sys.isNative){
                return;
            }

            //语音
            Panel_audio.setVisible(true);

            Panel_chat.setVisible(true);
            Image_chat.setVisible(true);
            Image_chat.setContentSize(cc.size(70, 64));

            //语音信息
            var intArray = [];
            var vmsg = userChatMsg.vmsg;
            var lenght = vmsg.limit - vmsg.offset;
            for (var i = 0; i < lenght; i++){
                intArray.push(vmsg.view[i + vmsg.offset]);
            }

            var millisecond = mo.gameHelper.getMillisecond().toString();
            var fileName = millisecond + ".amr";
            mo.nativeHelper.playFile(fileName, intArray);

            var time = (lenght / 1500);
            Panel_chat.runAction(
                cc.sequence(
                    cc.delayTime(time),
                    cc.hide()
                )
            );
        }
    },

    //设置离线状态
    setPlayerOnlineStats : function(onlineInfo){
        //重置
        for (var i = 0; i < 5; i++) {
            this.mPlayer[i].setOnlineStatus(false);
        }

        //设置状态
        if (this.mPlayerInfos != null){
            for (var i = 0; i < 5; i++) {
                if (this.mPlayerInfos[i] == null){
                    continue;
                }
                var uid = this.mPlayerInfos[i].user_info.userid;

                if (onlineInfo[uid.toString()] != undefined && onlineInfo[uid.toString()] == 0){
                    this.mPlayer[i].setOnlineStatus(true);
                }
            }
        }
    },

    //设置选择牌按钮状态 status 0五牛 1有牛
    setSelectCardButtonStatus : function(status, big){
        mo.seekWidgetByName(this.Panel_otc, "Button_niuTishi").setVisible(true);
        mo.seekWidgetByName(this.Panel_otc, "Button_niuWu").setVisible(false);
        mo.seekWidgetByName(this.Panel_otc, "Button_niuYou").setVisible(false);

        var img = mo.seekWidgetByName(mo.seekWidgetByName(this.Panel_otc, "Button_niuYou"), "Image_text");
        if (status == 1){
            mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_youniu.png");
        }

        if (big != undefined){
            if (big == 1){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_wuxiaoniu.png");
            }else if (big == 2){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_zhadan.png");
            }else if (big == 3){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_wuhuaniu.png");
            }else if (big == 17){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_zhadan.png");
            }else if (big == 18){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_wuhuaniu.png");
            }else if (big == 19){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_wuxiaoniu.png");
            }else if (big == 20){
                mo.gameHelper.loadTextureImage(img, "res/ccs/nn/btn/text_fulu.png");
            }
        }
    },

    //发牌
    setFapaiAnim : function(cardNumss){
        var delayTime = 1;
        for (var i = 0; i < cardNumss.length; i++){
            if (cardNumss[i].length != 0){
                delayTime += 0.05;
            }
        }

        for (var i = 0; i < 5; i++){
            var Button_bet = this.mButton_bets[i];
            if (Button_bet.isVisible()){
                Button_bet.stopAllActions();
                Button_bet.setVisible(false);
                Button_bet.runAction(cc.sequence(
                    cc.delayTime(delayTime),
                    cc.show()
                ));
            }
        }
    },

    //设置录像隐藏
    setIsReplay : function(isReplay){
        mo.seekWidgetByName(this.ccsNode, "Button_setting").setVisible(!isReplay);
        mo.seekWidgetByName(this.ccsNode, "Button_chat").setVisible(!isReplay);
        this.mKwxSysInfoWidget.setVisible(!isReplay);
        if (this.mNnTableMicLayer != null){
            this.mNnTableMicLayer.setVisible(!isReplay);
        }

    },

    //设置加倍次数
    setBetInfo : function(newActionList){
        var betBtns = [];
        for (var i = 0; i < 5; i++){
            var btn = this.mButton_bets[i];
            if (i < newActionList.length){
                betBtns.push(btn);
                btn.setVisible(true);
                //多少倍写死了
                var beiNum = newActionList[i].Rate * mo.nnTable.mGameConfig.basepoint;
                var betStr = "res/ccs/nn/btn/bet_" + beiNum +  ".png";
                var Image_text = mo.seekWidgetByName(btn, "Image_text");
                mo.gameHelper.loadTextureImage(Image_text, betStr);
            }else{
                btn.setVisible(false);
            }
        }

        var startP = -(betBtns.length - 1) * 120 / 2;
        for (var i = 0; i < betBtns.length; i++){
            betBtns[i].setPositionX(startP + 120 * i);
        }
    },

    //踢人
    setKickPlayerForViewSeat : function(viewSeat){
        var logicSeat = mo.nnTableStatus.getLogicForView(viewSeat, mo.nnTableStatus.mTableStatus.MySeat - 1) + 1;
        var SeatUser = mo.nnTableStatus.mTableStatus["SeatUser" + logicSeat];
        if (SeatUser != null){
            mo.showMsgDialogOkAndCancel("确定要踢掉玩家[" + SeatUser.user_info.nickname + "]吗?", function(){
                mo.gameMsgManager.sendCreateUserKickOutRequestnn(SeatUser.user_info.userid);
            }, this, function(){}, this);
        }
    },

    //倒计时
    ontUpdateTimeLeft : function(dt){
        this.mTimeLeft -= dt;
        if (this.mTimeLeft <= 0){
            this.mTimeLeft = 0;
            //发送结束消息
            mo.nnTableStatus.sendKaiPai();

            this.unschedule(this.ontUpdateTimeLeft);
        }
        mo.seekWidgetByName(this.Image_timeBg, "BitmapFontLabel_time").setString("" + parseInt(this.mTimeLeft));
        var percent = this.mTimeLeft / 10.0;
        this.mProgressTimer.setPercentage(percent * 100);
    },

    //礼包
    setChatMsgReward : function(userChatMsg){
        var kwxRewardLayer = new KwxRewardLayer();
        this.addChild(kwxRewardLayer);
        var toPlayer = mo.nnTableStatus.getViewSeatForUid(userChatMsg.uid);
        kwxRewardLayer.startAction(userChatMsg.msg, this.mPlayerPoss[toPlayer], toPlayer);
    }
});